from rest_framework import serializers

from apps.headline.models import Article
from apps.headline.serializers.fans import FansModelSerializer
from apps.users.models import User


class UserArticlesModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Article
        fields = ('id', 'title')


class UserModelSerializer(serializers.ModelSerializer):
    articles = UserArticlesModelSerializer(many=True)
    fans = FansModelSerializer(many=True)
    # username = serializers.SerializerMethodField()

    class Meta:
        model = User
        fields = ['id', 'avatar', 'articles', 'fans', 'username']
        # fields = '__all__'


# class UserCommentModelSerializer(serializers.ModelSerializer):
#     articles = UserArticlesModelSerializer(many=True)
#     fans = FansModelSerializer(many=True)
#     # username = serializers.SerializerMethodField()
#
#     class Meta:
#         model = User
#         # fields = ['id', 'avatar', 'articles', 'fans', 'username']
#         fields = '__all__'

    # def get_username(self, obj):
    #     a = obj
    #     return obj.nickname


